package com.cxx.home.controller;

import com.cxx.common.ReadView;
import com.cxx.common.WriteView;
import com.cxx.home.dto.asset.AssetDto;
import com.cxx.home.service.AssetService;
import com.fasterxml.jackson.annotation.JsonView;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/asset")
@Tag(name = "资产")
public class AssetController {
    @Resource
    private AssetService assetService;

    @Operation(summary = "查询资产")
    @GetMapping("")
    public @JsonView(ReadView.class) List<AssetDto> queryAsset(@RequestParam("category") String category) {
        return assetService.queryAsset(category);
    }

    @Operation(summary = "新增资产")
    @PostMapping("")
    public Boolean addAsset(@RequestBody @JsonView(WriteView.class) @Validated AssetDto assetDto) {
        return assetService.addAsset(assetDto);
    }

    @Operation(summary = "更新资产")
    @PutMapping("/{id}")
    public Boolean updateAsset(@PathVariable("id") long id,
                               @RequestBody @JsonView(WriteView.class) AssetDto assetDto) {
        return assetService.updateAsset(id, assetDto);
    }

    @Operation(summary = "删除资产")
    @DeleteMapping("/{id}")
    public Boolean deleteAsset(@PathVariable("id") long id) {
        return assetService.deleteAsset(id);
    }

    @Operation(summary = "查询资产类别")
    @GetMapping("/category")
    public List<String> queryAssetCategory() {
        return assetService.queryAssetCategory();
    }
}
    